if (!(typeof jQuery == 'undefined')) {

//as soon as the DOM is ready, run this function to manipulate it
$(function() {
    // prevent the default behaviour of link
    $('.channeltable').find('td.click').find('a').click(function(event){
        event.preventDefault();
    });

    // get all tr elements in the table 'tableForms' and bind a
    // function to their click event
    $('.channeltable').find('td.click').bind('click',function(e){
    	// get all of this row's sibblings and hide their forms.
    	$(this).siblings().not(this).find('div.desc').hide();
        $(this).siblings().not(this).removeClass('clicked');

        if ($(this).find('div.desc').is(":hidden")) {
    	// now show the current row's form
            $(this).find('div.desc').fadeIn('slow');
            $(this).addClass('clicked');
            $(this).find('div.desc').html($(this).find('a.prog').attr('title'));

        } else {
            $(this).find('div.desc').fadeOut('fast');
            $(this).removeClass('clicked');
        }
    }).
    // now that the click event is bound, hide all of the forms in this table
    find('div.desc').hide();

    /* automatically submit if any element in the form with class auto_submit changes */
    $(".auto_submit").change(function() {
        this.submit();
    });
});

} else {

/* Simple javascript without jquery for older mobile browsers */
function toggle(obj) {
	var el = document.getElementById(obj);
        var el2 = document.getElementById(obj+'_div');
        if (el2.innerHTML != el.title) {
            el2.innerHTML = el.title;
            row = el2.parentNode.parentNode
            c = row.getAttribute('class')
            row.setAttribute('class', c+' clicked');
            img = el2.parentNode.getElementsByTagName('img')[0];
            img.src='images/minus.png';

        } else {
            el2.innerHTML = '';
            row = el2.parentNode.parentNode
            row.setAttribute('class', row.getAttribute('class').replace('clicked', ''));
            img = el2.parentNode.getElementsByTagName('img')[0];
            img.src='images/plus.png';
        }
}
}
